package game.engine;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


/**
 * 
 * Class which will support some type of file containing level info
 * 
 * @author mah75
 * 
 */
public abstract class LevelParser {

    private File myFile;

    /**
     * 
     * @param file File to parse.
     */
    public LevelParser (File file) {
        myFile = file;
    }

    /**
     * Determines whether a parser has valid information.
     * 
     * @return true or false based on validity
     */
    public abstract boolean isValid ();

    /**
     * 
     * @return The main element in a file to be parsed (in Xml->root, in others->name)
     */
    public abstract Object getRootElement ();

    /**
     * 
     * @param element The section of a file to be parsed
     * @param name The name of the desired field
     * @return The collection of values returned
     */
    public abstract NodeList getElementsByName (Element element, String name);

    /**
     * 
     * @param element The section of a file to be parsed
     * @param getString The name of the field whose text is desired
     * @return The text string in the field
     */
    public abstract String getTextContent (Element element, String getString);

    /**
     * 
     * @param method String name of the method to be used
     * @param argument String argument passed into the method
     */
    public void reflectMethod (String method, String argument) {
        try {
            Method testMethod = XmlParser.class.getMethod(method, String.class);
            testMethod.invoke(new XmlParser(myFile), argument);
        }
        catch (SecurityException e) {
            e.printStackTrace();
        }
        catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
